package br.com.listadecompras.utils;

import br.com.listadecompras.DAO.GroupDAO;
import br.com.listadecompras.DAO.ItemDAO;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {
	
    public static final int DATABASE_VERSION = 1;
	
    private String createTable = null;
    
	public DBHelper(Context context, String dataBaseName) {
		super(context, dataBaseName, null, DATABASE_VERSION);
	}
	
	public DBHelper(Context context, String dataBaseName, String createTable) {
		super(context, dataBaseName, null, DATABASE_VERSION);
		
		this.createTable = createTable;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		if ((this.createTable != null) && (this.createTable != ""))
			db.execSQL(this.createTable);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		
		db.execSQL("DROP TABLE IF EXISTS " + ItemDAO.TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + GroupDAO.TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + Constantes.DataBaseConstantes.AuxTables.TABLE_GROUP_ITENS_NAME);
	}
}
